'use strict';

const Controller = require('egg').Controller;
/**
* @controller OnuProfileController 注释必写，swagger-doc是根据这段注释来生成接口的 ）。
*/
class OnuProfileController extends Controller {
  async list() {
        /**
        * @summary onuprofilelist。
        * @description onuprofilelist。
        * @router get /onuprofilelist
        * @request query String OltId
        * @request query String search
        */
    const params = this.ctx.query
    const result = await this.ctx.service.onuProfile.list(params)
    this.ctx.body = {
        msg:"",
        status:200,
        data: result.rows,
        count: result.count,
    }
  }
  async allList() {
    /**
      * @summary onuprofilealllist。
      * @description onuprofilealllist。
      * @router get /onuprofilealllist
      * @request query String OltId
    */
    const params = this.ctx.query
    const result = await this.ctx.service.onuProfile.allList(params)
    this.ctx.body = {
      msg:"",
      status:200,
      data:result
    }
  }
  async create() {
    const params = this.ctx.request.body
    let oltResult = await this.ctx.model.Olt.findOne({_id:params.oltId})
    const result = await this.ctx.service.onuProfile.create(params)
    global.log.desc = ` ${oltResult.name} ${oltResult.oltIP} `+result.msg
    this.ctx.body = {
      data:result,
      status:200
    }
  }
  async edit() {
    const params = this.ctx.request.body
    let oltResult = await this.ctx.model.Olt.findOne({_id:params.oltId})
    const result = await this.ctx.service.onuProfile.edit(params)
    global.log.desc = ` ${oltResult.name} ${oltResult.oltIP} `+result.msg
    this.ctx.body = {
      data:result,
      status:200
    }
  }
  async delete(){
    const params = this.ctx.query
    let onuTypeResult = await this.ctx.model.OnuProfile.findOne({_id:params.id})
    let oltResult = await this.ctx.model.Olt.findOne({_id:onuTypeResult.oltId})
    const result = await this.ctx.service.onuProfile.delete(params)
    global.log.desc = ` ${oltResult.name} ${oltResult.oltIP} `+result.msg
    this.ctx.body = {
      data:result,
      status:200
    }
  }
  async getOnuProfileMsg() {
    const params = this.ctx.query
    const result = await this.ctx.service.onuProfile.getOnuProfileMsg(params);
    this.ctx.body = {
      result:result.data,
      flag:result.flag,
      msg:result.msg
    }
  }
}

module.exports = OnuProfileController;
